function t(t) {
    if (Array.isArray(t)) {
        for (var a = 0, e = Array(t.length); a < t.length; a++) e[a] = t[a];
        return e;
    }
    return Array.from(t);
}

var a = require("../../utils/requestApi.js");

Page({
    data: {
        chatList: [],
        currentPage: 1,
        isLoading: !1,
        fullyLoaded: !1,
        limit: 10
    },
    onLoad: function(t) {
        wx.showLoading({
            title: "请稍候...",
            mask: !0
        });
        var e = this, i = {
            status: 1
        }, n = "";
        if (t.collectionId) {
            var o = t.title;
            wx.setNavigationBarTitle({
                title: o
            }), i.collectionId = t.collectionId, n = "没有更多了～";
        } else wx.setNavigationBarTitle({
            title: "学习学习土味情话"
        }), i.$or = [ {
            collectionId: ""
        }, {
            collectionId: null
        } ], n = "刷完啦～每天都会更新，记得回来看看喔！";
        e.setData({
            where: i,
            fullyLoadedText: n
        });
        var r = {
            where: i,
            limit: e.data.limit,
            page: e.data.currentPage,
            order: [ [ "createdAt", "DESC" ] ]
        };
        a.getChatList(r).then(function(t) {
            wx.hideLoading(), !0 === t.result && e.setData({
                chatList: t.obj
            });
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        var t = this;
        wx.showNavigationBarLoading(), setTimeout(function() {
            t.setData({
                currentPage: 1,
                fullyLoaded: !1
            });
            var e = {
                where: t.data.where,
                limit: t.data.limit,
                page: t.data.currentPage,
                order: [ [ "createdAt", "DESC" ] ]
            };
            a.getChatList(e).then(function(a) {
                wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(), !0 === a.result && t.setData({
                    chatList: a.obj
                });
            });
        }, 500);
    },
    onReachBottom: function() {
        var e = this;
        if (!e.data.isLoading && !e.data.fullyLoaded) {
            wx.showNavigationBarLoading(), e.setData({
                currentPage: e.data.currentPage + 1,
                isLoading: !0
            });
            var i = {
                where: e.data.where,
                limit: e.data.limit,
                page: e.data.currentPage,
                order: [ [ "createdAt", "DESC" ] ]
            };
            a.getChatList(i).then(function(a) {
                if (wx.hideNavigationBarLoading(), !0 === a.result) {
                    var i = {
                        chatList: [].concat(t(e.data.chatList), t(a.obj)),
                        isLoading: !1
                    };
                    a.obj.length < e.data.limit && (i.fullyLoaded = !0), e.setData(i);
                }
            });
        }
    },
    onShareAppMessage: function() {
        return {
            title: "土味情话合集",
            path: "/pages/index3/index3",
            imageUrl: "../../resource/img/xindong.jpg"
        };
    }
});